package org.kfive.nova.aop;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import org.apache.log4j.Logger;

import java.lang.reflect.Method;

/**
 * Created with IntelliJ IDEA.
 * User: admin
 * Date: 16-2-29
 * Time: 下午9:40
 * To change this template use File | Settings | File Templates.
 */
public class CGLibManProxy implements MethodInterceptor {

    private static Logger LOG = Logger.getLogger(CGLibManProxy.class);

    private Object targetObject;

    public Object createProxyObject(Object targetObject){
        this.targetObject = targetObject;
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(this.targetObject.getClass());
        enhancer.setCallback(this);
        return enhancer.create();

    }
    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        LOG.debug("before start sleep");
        return methodProxy.invokeSuper(o,objects);
        //return method.invoke(this.targetObject,objects);
    }
}
